from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-10 14:02:12.956009
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 10, Jun, 2022
Time: 14:02:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5164
Nobs: 683.000 HQIC: -49.8820
Log likelihood: 8481.33 FPE: 1.72293e-22
AIC: -50.1129 Det(Omega_mle): 1.51166e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.308955 0.058995 5.237 0.000
L1.Burgenland 0.105806 0.038312 2.762 0.006
L1.Kärnten -0.109203 0.020202 -5.406 0.000
L1.Niederösterreich 0.201157 0.079927 2.517 0.012
L1.Oberösterreich 0.115417 0.078706 1.466 0.143
L1.Salzburg 0.255718 0.040860 6.258 0.000
L1.Steiermark 0.045254 0.053481 0.846 0.397
L1.Tirol 0.108381 0.043222 2.508 0.012
L1.Vorarlberg -0.056748 0.037724 -1.504 0.133
L1.Wien 0.029960 0.069664 0.430 0.667
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.043540 0.124759 0.349 0.727
L1.Burgenland -0.033804 0.081019 -0.417 0.677
L1.Kärnten 0.039951 0.042722 0.935 0.350
L1.Niederösterreich -0.181455 0.169026 -1.074 0.283
L1.Oberösterreich 0.439177 0.166444 2.639 0.008
L1.Salzburg 0.285197 0.086408 3.301 0.001
L1.Steiermark 0.106853 0.113098 0.945 0.345
L1.Tirol 0.316733 0.091404 3.465 0.001
L1.Vorarlberg 0.027682 0.079777 0.347 0.729
L1.Wien -0.036321 0.147321 -0.247 0.805
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189385 0.030304 6.249 0.000
L1.Burgenland 0.088783 0.019680 4.511 0.000
L1.Kärnten -0.007671 0.010377 -0.739 0.460
L1.Niederösterreich 0.258306 0.041057 6.291 0.000
L1.Oberösterreich 0.143598 0.040430 3.552 0.000
L1.Salzburg 0.045149 0.020989 2.151 0.031
L1.Steiermark 0.023131 0.027472 0.842 0.400
L1.Tirol 0.089475 0.022202 4.030 0.000
L1.Vorarlberg 0.057579 0.019378 2.971 0.003
L1.Wien 0.113355 0.035785 3.168 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114314 0.030564 3.740 0.000
L1.Burgenland 0.044654 0.019849 2.250 0.024
L1.Kärnten -0.014025 0.010466 -1.340 0.180
L1.Niederösterreich 0.186283 0.041409 4.499 0.000
L1.Oberösterreich 0.314538 0.040776 7.714 0.000
L1.Salzburg 0.103279 0.021169 4.879 0.000
L1.Steiermark 0.106759 0.027707 3.853 0.000
L1.Tirol 0.102703 0.022393 4.586 0.000
L1.Vorarlberg 0.067981 0.019544 3.478 0.001
L1.Wien -0.027469 0.036092 -0.761 0.447
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123425 0.056259 2.194 0.028
L1.Burgenland -0.047570 0.036535 -1.302 0.193
L1.Kärnten -0.045995 0.019265 -2.388 0.017
L1.Niederösterreich 0.147248 0.076221 1.932 0.053
L1.Oberösterreich 0.150516 0.075057 2.005 0.045
L1.Salzburg 0.282343 0.038965 7.246 0.000
L1.Steiermark 0.052398 0.051001 1.027 0.304
L1.Tirol 0.168109 0.041218 4.079 0.000
L1.Vorarlberg 0.097798 0.035975 2.719 0.007
L1.Wien 0.074177 0.066433 1.117 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062023 0.044477 1.394 0.163
L1.Burgenland 0.031996 0.028884 1.108 0.268
L1.Kärnten 0.051339 0.015231 3.371 0.001
L1.Niederösterreich 0.207260 0.060259 3.440 0.001
L1.Oberösterreich 0.303894 0.059338 5.121 0.000
L1.Salzburg 0.043400 0.030805 1.409 0.159
L1.Steiermark 0.007253 0.040320 0.180 0.857
L1.Tirol 0.136944 0.032586 4.203 0.000
L1.Vorarlberg 0.074291 0.028441 2.612 0.009
L1.Wien 0.082136 0.052521 1.564 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170089 0.053338 3.189 0.001
L1.Burgenland 0.001188 0.034638 0.034 0.973
L1.Kärnten -0.064183 0.018265 -3.514 0.000
L1.Niederösterreich -0.089495 0.072264 -1.238 0.216
L1.Oberösterreich 0.199175 0.071160 2.799 0.005
L1.Salzburg 0.055130 0.036942 1.492 0.136
L1.Steiermark 0.241527 0.048353 4.995 0.000
L1.Tirol 0.499668 0.039078 12.786 0.000
L1.Vorarlberg 0.053481 0.034108 1.568 0.117
L1.Wien -0.064146 0.062985 -1.018 0.308
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154945 0.060111 2.578 0.010
L1.Burgenland -0.007412 0.039037 -0.190 0.849
L1.Kärnten 0.062079 0.020584 3.016 0.003
L1.Niederösterreich 0.193983 0.081440 2.382 0.017
L1.Oberösterreich -0.070829 0.080196 -0.883 0.377
L1.Salzburg 0.208277 0.041633 5.003 0.000
L1.Steiermark 0.134957 0.054493 2.477 0.013
L1.Tirol 0.069301 0.044041 1.574 0.116
L1.Vorarlberg 0.133768 0.038439 3.480 0.001
L1.Wien 0.123343 0.070983 1.738 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374644 0.035062 10.685 0.000
L1.Burgenland 0.000638 0.022770 0.028 0.978
L1.Kärnten -0.022555 0.012007 -1.879 0.060
L1.Niederösterreich 0.216287 0.047503 4.553 0.000
L1.Oberösterreich 0.214059 0.046777 4.576 0.000
L1.Salzburg 0.042360 0.024284 1.744 0.081
L1.Steiermark -0.018669 0.031785 -0.587 0.557
L1.Tirol 0.101906 0.025688 3.967 0.000
L1.Vorarlberg 0.064723 0.022421 2.887 0.004
L1.Wien 0.028546 0.041403 0.689 0.491
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037926 0.127236 0.184660 0.148991 0.107994 0.089654 0.047538 0.213787
Kärnten 0.037926 1.000000 -0.017412 0.134527 0.053528 0.092381 0.439181 -0.057226 0.093997
Niederösterreich 0.127236 -0.017412 1.000000 0.332288 0.136743 0.289584 0.081951 0.169012 0.309265
Oberösterreich 0.184660 0.134527 0.332288 1.000000 0.224575 0.316666 0.168456 0.154145 0.261823
Salzburg 0.148991 0.053528 0.136743 0.224575 1.000000 0.134334 0.105831 0.125945 0.133176
Steiermark 0.107994 0.092381 0.289584 0.316666 0.134334 1.000000 0.140982 0.119178 0.063830
Tirol 0.089654 0.439181 0.081951 0.168456 0.105831 0.140982 1.000000 0.093163 0.145088
Vorarlberg 0.047538 -0.057226 0.169012 0.154145 0.125945 0.119178 0.093163 1.000000 0.006891
Wien 0.213787 0.093997 0.309265 0.261823 0.133176 0.063830 0.145088 0.006891 1.000000